package com.cxf.windex.biz;

import com.cxf.windex.base.biz.BaseBiz;
import com.cxf.windex.base.common.ServiceException;
import com.cxf.windex.base.constant.UserConstant;
import com.cxf.windex.base.util.IdUtil;
import com.cxf.windex.entity.Activity;
import com.cxf.windex.entity.BConfig;
import com.cxf.windex.entity.BShop;
import com.cxf.windex.mapper.BConfigMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @program: business_needs
 * @description: 分配配置
 * @author: chenxf
 * @create: 2018-11-07 09:27
 **/
@Service
public class BConfigBiz extends BaseBiz<BConfigMapper,BConfig> {


  /**
   * 获取广告分成信息
   * @param status 1 普通  2 广告商
   * @return
   */
  public BConfig getInfo(String status) {
    Example example = new Example(BConfig.class);
    example.createCriteria().andEqualTo("status", status);
    example.setOrderByClause("crt_time desc" );
    PageHelper.startPage(1, 1);
    return selectByExample(example).get(0);
  }

  /**
   * 保存广告提成配置
   * @param entity
   */
  public void save(BConfig entity){
      if(entity.getLF().add(entity.getLFP()).add(entity.getLLP()).intValue()>100){
        throw new ServiceException("海报分成比例超过100");
      }
    if(entity.getVF().add(entity.getVFP()).add(entity.getVLP()).intValue()>100){
      throw new ServiceException("语音分成比例超过100");
    }
      entity.setId(UserConstant.ORDERS_ID_PREX+new IdUtil(5,1).nextId());
      insertSelective(entity);

  }
}
